package com.xq;

import com.xq.Handler.*;
import com.xq.Scene;

import java.util.HashMap;
import java.util.Scanner;

public class Game {
    Hunter hunter = Hunter.getHunter();
    private HashMap<String, Handler> handlers = new HashMap<String, Handler>();
    private Monster m1,m2,m3,m4,m5;

    public Game()
    {
        Scene scene = new Scene();
        scene.initScene();
        handlers.put("go", new HandlerGo(this));
        handlers.put("bye", new HandlerBye(this));
        handlers.put("help", new HandlerHelp(this));
        handlers.put("fight", new HandlerFight(this));
        handlers.put("use", new HandlerUse(this));
        handlers.put("view", new HandlerView(this));
        handlers.put("check", new HandlerCheck(this));
    }

    private void printWelcome() {
        System.out.println();
        System.out.println("欢迎来到城堡！");
        System.out.println("如果需要帮助，请输入 'help' 。");
        System.out.println();
        System.out.print("为你的角色命名：");
        Scanner on = new Scanner(System.in);
        String setname = on.nextLine();
        Hunter.getHunter().setName(setname);
        showPrompt();
    }

    // 以下为用户命令

    public void goRoom(String direction)
    {
        Room nextRoom = hunter.getCurrentRoom().getExit(direction);

        if (nextRoom == null) {
            System.out.println("那里没有门！");
        }
        else {
            hunter.setCurrentRoom(nextRoom);
            showPrompt();
        }
    }

    public void showPrompt() {
        System.out.println("你在" + hunter.getCurrentRoom());
        System.out.println("出现了" + hunter.getCurrentRoom().getMonster().getType());
        if (hunter.getCurrentRoom().getProps() != null) {
            hunter.getProps(hunter.getCurrentRoom().getProps().getName(), hunter.getCurrentRoom().getProps());
            hunter.getCurrentRoom().cleanProps();
        }
        System.out.print("出口有: ");
        System.out.print(hunter.getCurrentRoom().getExitDesc());
        System.out.println();
    }

    public void play(){
        Scanner in = new Scanner(System.in);
        while ( true ) {
            String line = in.nextLine();
            String[] words = line.split(" ");
            Handler handler = handlers.get(words[0]);
            String value = "";
            if (words.length > 1)
                value = words[1];
            if (handler != null){
                handler.doCmd(value);
                if (handler.isBye() )
                    break;
            } else {
                System.out.println("请输入正确指令！");
            }

        }
        in.close();
    }

    public static void main(String[] args) {
        Game game = new Game();
        game.printWelcome();
        game.play();

        System.out.println("感谢您的光临。再见！");

    }
}

